<?xml version="1.0" encoding="UTF-8"?>
<!--

       Copyright 2006-2020 the original author or authors.

       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.

-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>The &lt;context&gt; Element</title>
  <link rel="stylesheet" type="text/css" href="../mbgstyle.css" />
</head>
<body>
<h1>The &lt;context&gt; Element</h1>
<p>The &lt;context&gt; element is used to specify the environment for
generating a set of objects.  Child elements are used to specify the database
to connect to, the type of objects to generate, and the tables to introspect.
Multiple &lt;context&gt; elements can be listed inside an
<a href="generatorConfiguration.html">&lt;generatorConfiguration&gt;</a>
element to allow generating objects from different
databases, or with different generation parameters, in the same run of MyBatis Generator (MBG).</p>

<h2>Required Attributes</h2>
<table border="1" cellspacing="0" cellpadding="5">
  <tr>
    <th>Attribute</th>
    <th>Description</th>
  </tr>
  <tr>
    <td>id</td>
    <td>A unique identifier for this context.  This value will be used in some
      error messages.</td>
  </tr>
</table>

<h2>Optional Attributes</h2>
<table border="1" cellspacing="0" cellpadding="5">
  <tr>
    <th>Attribute</th>
    <th>Description</th>
  </tr>
  <tr>
    <td valign="top">defaultModelType</td>
    <td>
      <i>This attribute is ignored if the target runtime is "MyBatis3Simple", "MyBatis3DynamicSql",
       or "MyBatis3Kotlin"</i><br/>
      This attribute is used to set the default for generated model types.
      The model type defines how MBG will generate domain classes.  With some
      model types MBG will generate a single domain class for each table,
      with others MBG may generate different classes depending on the structure
      of the table.  The property supports these values:
      <table>
        <tr>
          <th valign="top">conditional</th>
          <td><i>This is the default value</i>
              <br/>This model is similar to the hierarchical model except that a separate
                   class will not be generated if that separate class would only contain
                   one field.  So if a table has only one primary key field, that field
                   will be merged into the base record class.</td>
        </tr>
        <tr>
          <th valign="top">flat</th>
          <td>This model generates only one domain class for any table.  The class
              will hold all fields in the table.</td>
        </tr>
        <tr>
          <th valign="top">hierarchical</th>
          <td>This model will generate a primary key class if the table has
              a primary key, another class that holds any BLOB columns in the table, and
              another class that holds the remaining fields.  There is an appropriate
              inheritance relationship between the classes.</td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td valign="top">targetRuntime</td>
    <td>
      This property is used to specify the runtime target for generated code.
      The property supports these special values:
      <table>
        <tr>
          <th valign="top">MyBatis3DynamicSql</th>
          <td><i>This is the default value</i><br/>
            With the value, MBG will generate objects that are compatible
            with MyBatis versions 3.4.2 and higher, and Java 8 and higher (e.g. the
            Java model and mapper interfaces will use generic types and other Java 8
            features like default methods in interfaces).
            <p><b>Important:</b> The Java code generated with this target runtime is dependent on the 
            "MyBatis Dynamic SQL" support library version 1.1.3 or higher.</p>
            <p>Other important information:</p>
            <ul>
              <li>The model objects are generated in the "FLAT" style regardless of what is specified
                  for the "defaultModelType".  This also means that there are no "with BLOBs" and
                  "without BLOBs" methods.</li>
              <li>The mappers are generated as annotated mappers regardless of what is specified
                  for the "type" of &lt;javaClientGenerator&gt;.</li>
              <li>No XML will be generated. &lt;sqlMapGenerator&gt; is not required and will be ignored if specified.</li>
              <li>MyBatis Dynamic SQL supports table aliases in a "per query" manner rather than the "all or nothing"
                  manner of the other runtimes.  For this reason, configured table aliases are ignored.</li>
            </ul>
          </td>
        </tr>
        <tr>
          <th valign="top">MyBatis3Kotlin</th>
          <td>
            With the value, MBG will generate Kotlin objects that are compatible
            with MyBatis versions 3.4.2 and higher.
            <p><b>Important:</b> The Kotlin code generated with this target runtime is dependent on the 
            "MyBatis Dynamic SQL" support library version 1.1.4 or higher.</p>
            <p>Other important information:</p>
            <ul>
              <li>The model objects are generated in the "FLAT" style regardless of what is specified
                  for the "defaultModelType".  This also means that there are no "with BLOBs" and
                  "without BLOBs" methods.</li>
              <li>The mappers are generated as annotated mappers regardless of what is specified
                  for the "type" of &lt;javaClientGenerator&gt;.</li>
              <li>No XML will be generated. &lt;sqlMapGenerator&gt; is not required and will be ignored if specified.</li>
              <li>MyBatis Dynamic SQL supports table aliases in a "per query" manner rather than the "all or nothing"
                  manner of the other runtimes.  For this reason, configured table aliases are ignored.</li>
            </ul>
          </td>
        </tr>
        <tr>
          <th valign="top">MyBatis3</th>
          <td>With the value, MBG will generate objects that are compatible
            with MyBatis versions 3.0 and higher, and JSE 5.0 and higher (e.g. the
            Java model and mapper interfaces will use generic types).
            The "by example" methods in these generated objects support virtually
            unlimited dynamic where clauses.  Additionally, the Java objects
            generated with these generators support many JSE 5.0 features including
            parameterized types and annotations.</td>
        </tr>
        <tr>
          <th valign="top">MyBatis3Simple</th>
          <td>
            With the value, MBG will generate objects that are compatible
            with MyBatis versions 3.0 and higher, and JSE 5.0 and higher (e.g. the
            Java model and mapper interfaces will use generic types).
            The mappers generated with this target runtime are very basic
            CRUD operations only with no "by example" methods and very little
            dynamic SQL.  The Java objects
            generated with these generators support many JSE 5.0 features including
            parameterized types and annotations.</td>
        </tr>
      </table>
      <p>If you want to create a different code generator in entirety,
         then use this value to specify the fully qualified name of a
         class that extends <code>org.mybatis.generator.api.IntrospectedTable</code>.
         With this, you can create your own code generator and plug
         it in to the code generation engine.  See the
         <a href="../reference/extending.html">Extending MyBatis Generator</a> page for more information.
      </p>
    </td>
  </tr>
  <tr>
    <td valign="top">introspectedColumnImpl</td>
    <td>Use this value to specify the fully qualified name of a
        class that extends <code>org.mybatis.generator.api.IntrospectedColumn</code>.
        This is used if you want to change the behavior of the code generators
        when calculating column information.  See the
        <a href="../reference/extending.html">Extending MyBatis Generator</a> page for more information.</td>
  </tr>
</table>

<h2>Child Elements</h2>
<ul>
  <li><a href="property.html">&lt;property&gt;</a> (0..N)</li>
  <li><a href="plugin.html">&lt;plugin&gt;</a> (0..N)</li>
  <li><a href="commentGenerator.html">&lt;commentGenerator&gt;</a> (0 or 1)</li>
  <li><a href="connectionFactory.html">&lt;connectionFactory&gt;</a> (either connectionFactory or jdbcConnection is Required)</li>
  <li><a href="jdbcConnection.html">&lt;jdbcConnection&gt;</a> (either connectionFactory or jdbcConnection is Required)</li>
  <li><a href="javaTypeResolver.html">&lt;javaTypeResolver&gt;</a> (0 or 1)</li>
  <li><a href="javaModelGenerator.html">&lt;javaModelGenerator&gt;</a> (1 Required)</li>
  <li><a href="sqlMapGenerator.html">&lt;sqlMapGenerator&gt;</a> (0 or 1)</li>
  <li><a href="javaClientGenerator.html">&lt;javaClientGenerator&gt;</a> (0 or 1)</li>
  <li><a href="table.html">&lt;table&gt;</a> (1..N)</li>
</ul>

<h2>Supported Properties</h2>
<p>This table lists the properties that can be
specified with the <a href="property.html">&lt;property&gt;</a> child element:</p>
<table border="1" cellspacing="0" cellpadding="5">
  <tr>
    <th>Property Name</th>
    <th>Property Values</th>
  </tr>
  <tr>
    <td valign="top">autoDelimitKeywords</td>
    <td>If true, then MBG will delimit SQL keywords if they are used as
      column names in tables.
      MBG maintains a list of SQL keywords
      for many different databases.  However, the list may not be
      totally comprehensive.  If a particular keyword is not on MBG's
      list, you may force the column to be delimited with a
      <code>&lt;columnOverride&gt;</code>.<p/>
      <p>See the source code for the class
      <code>org.mybatis.generator.internal.db.SqlReservedWords</code>
      for a list of keywords recognized by MBG.</p>
      <p><i>The default value is false.</i></p></td>
  </tr>
  <tr>
    <td valign="top">beginningDelimiter</td>
    <td>The value to use as the beginning identifier delimiter for SQL identifiers that
        require delimiters.  MBG will automatically delimit SQL identifiers if the
        identifier contains a space.  MBG will also delimit SQL identifiers if
        specifically requested in a &lt;table&gt; or  &lt;columnOverride&gt; configuration.<p/>
      <p><i>The default value is double quotes (&quot;).</i></p></td>
  </tr>
  <tr>
    <td valign="top">endingDelimiter</td>
    <td>The value to use as the ending identifier delimiter for SQL identifiers that
        require delimiters.  MBG will automatically delimit SQL identifiers if the
        identifier contains a space.  MBG will also delimit SQL identifiers if
        specifically requested in a &lt;table&gt; or  &lt;columnOverride&gt; configuration.<p/>
      <p><i>The default value is double quotes (&quot;).</i></p></td>
  </tr>
  <tr>
    <td valign="top">javaFileEncoding</td>
    <td>Use this property to specify an encoding to use when working with Java files.
        Newly generated Java files will be written to the file system in this encoding,
        and existing Java files will be read with this encoding when performing a merge.
        If not specified, then the platform default encoding will be used.
        <p/>
        <p>See <code>java.nio.charset.Charset</code> for information on valid encodings.</p>
    </td>
  </tr>
  <tr>
    <td valign="top">javaFormatter</td>
    <td>Use this property to specify the full class name of a user provided formatter for generated
        Java files.  The class must implement <code>org.mybatis.generator.api.JavaFormatter</code>
        and must have a default (no argument) constructor.  Each context holds a single instance
        of the Java formatter.  The default Java formatter is
        <code>org.mybatis.generator.api.dom.DefaultJavaFormatter</code>.
    </td>
  </tr>
  <tr>
    <td valign="top">kotlinFileEncoding</td>
    <td>Use this property to specify an encoding to use when working with Kotlin files.
        Newly generated Kotlin files will be written to the file system in this encoding.
        If not specified, then the platform default encoding will be used.
        <p/>
        <p>See <code>java.nio.charset.Charset</code> for information on valid encodings.</p>
    </td>
  </tr>
  <tr>
    <td valign="top">kotlinFormatter</td>
    <td>Use this property to specify the full class name of a user provided formatter for generated
        Kotlin files.  The class must implement <code>org.mybatis.generator.api.KotlinFormatter</code>
        and must have a default (no argument) constructor.  Each context holds a single instance
        of the Kotlin formatter.  The default Kotlin formatter is
        <code>org.mybatis.generator.api.dom.DefaultKotlinFormatter</code>.
    </td>
  </tr>
  <tr>
    <td valign="top">xmlFormatter</td>
    <td>Use this property to specify the full class name of a user provided formatter for generated
        XML files.  The class must implement <code>org.mybatis.generator.api.XmlFormatter</code>
        and must have a default (no argument) constructor.  Each context holds a single instance
        of the XML formatter.  The default XML formatter is
        <code>org.mybatis.generator.api.dom.DefaultXmlFormatter</code>.  The default formatter
        uses the formatting built into the XML DOM classes.
    </td>
  </tr>
</table>

</body>
</html>
